package com.example.demo

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import com.example.demo.databinding.ActivityMainBinding
import kotlin.concurrent.thread

private const val TAG = "MainActivity"

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val activityMainBinding = ActivityMainBinding.inflate(LayoutInflater.from(this))
        setContentView(activityMainBinding.root)
        activityMainBinding.createThread.setOnClickListener {
            val thread = Thread(Runnable {
                println("Hello, Java Thread")
            })
            thread.start()
        }

        activityMainBinding.methodCost.setOnClickListener {
            print1()
        }
    }

    override fun onStart() {
        super.onStart()
        Log.d(TAG, "onStart()")
    }

    override fun onResume() {
        super.onResume()
        thread {
            println("Hello, Kotlin Thread")
        }
        Log.d(TAG, "onResume()")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG, "onPause()")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG, "onStop()")
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    @MethodTimeCost
    private fun print1() {
        for (index in 1..1000) {
            Log.d(TAG, "print1(), index=${index}")
        }
    }

    private fun print2() {
        for (index in 1..1000) {
            Log.d(TAG, "print2(), index=${index}")
        }
    }
}